from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser
import allure
class ServiceLogin():
    def __init__(self,driver,base_url):
        #初始化该业务有关的页面类
        self.page_index=PageIndex(driver,base_url)
        self.page_login=PageLogin(driver,base_url)
        self.page_user=PageUser(driver,base_url)


    def service_login_001(self,d):
        #完成首页操作
        allure.attach('', '打开首页')
        self.page_index.openurl()
        allure.attach('','点击首页登录按钮')
        self.page_index.click_login()
        #完成登录页面操作
        self.page_login.input_zhanghao(d['zhanghao'])
        self.page_login.input_mima(d['mima'])
        self.page_login.click_loginbutton()
        #完成个人页面操作
        shiji=self.page_user.geth2text()
        yuqi=d['yuqi']
        #截图
        Name=self.page_user.jietu('denglu')
        allure.attach(open('./screen/' +Name+ '.png', 'rb').read(), "本次截图 ",
                      allure.attachment_type.PNG)
        return  shiji==yuqi

    def service_login_002(self,d):
        #完成首页操作
        self.page_index.openurl()
        self.page_index.click_login()
        #完成登录页面操作
        self.page_login.input_zhanghao(d['zhanghao'])
        self.page_login.input_mima(d['mima'])
        self.page_login.click_loginbutton()
        #完成个人页面操作
        shiji=self.page_login.getDIVtest()
        yuqi=d['yuqi']
        return  shiji==yuqi

    def service_login_003(self,d):
        #完成首页操作
        self.page_index.openurl()
        self.page_index.click_login()
        #完成登录页面操作
        self.page_login.input_zhanghao(d['zhanghao'])
        self.page_login.input_mima(d['mima'])
        self.page_login.click_loginbutton()
        #完成个人页面操作
        shiji=self.page_login.zhanghao_attr()
        yuqi=d['yuqi']
        return  yuqi  in shiji


    def service_login_004(self,d):
        #完成首页操作
        self.page_index.openurl()
        self.page_index.click_login()
        #完成登录页面操作
        self.page_login.input_zhanghao(d['zhanghao'])
        self.page_login.input_mima(d['mima'])
        self.page_login.click_loginbutton()
        #完成个人页面操作
        shiji=self.page_login.mima_attr()
        yuqi=d['yuqi']
        return  yuqi  in shiji